<?php
declare(strict_types=1);

use Phinx\Db\Adapter\MysqlAdapter;
use Phinx\Migration\AbstractMigration;

final class CreateTaskWorkOrderTable extends AbstractMigration
{
    public function up()
    {
        $this->table('task_work_order', ['id' => false, 'primary_key' => ['id'], 'engine' => 'InnoDB', 'collation' => 'utf8mb4_general_ci', 'comment' => '工单表'])
            ->addColumn('id', 'integer', ['identity' => true, 'signed' => false, 'limit' => 11, 'comment' => '主键ID'])
            ->addColumn('type', 'enum', ['values' => 'task_making,review_feedback', 'default' => 'task_making', 'comment' => '工单类型'])
            ->addColumn('number', 'string', ['default' => '', 'limit' => 15, 'comment' => '工单号'])
            ->addColumn('status', 'integer', ['signed' => false, 'limit' => MysqlAdapter::INT_TINY, 'default' => 0, 'comment' => '工单处理状态(0:未处理,1:已处理,2:已失效)'])
            ->addColumn('task_id', 'integer', ['signed' => false, 'limit' => 11, 'default' => 0, 'comment' => '任务id'])
            ->addColumn('version_id', 'integer', ['signed' => false, 'limit' => 11, 'default' => 0, 'comment' => '版本id'])
            ->addColumn('review_request_node_id', 'integer', ['signed' => false, 'limit' => 11, 'default' => 0, 'comment' => '审核节点id'])
            ->addColumn('created_by', 'integer', ['null' => false, 'default' => 0, 'limit' => 11, 'signed' => false, 'comment' => '创建人',])
            ->addColumn('receiver', 'integer', ['null' => false, 'default' => 0, 'limit' => 11, 'signed' => false, 'comment' => '处理人',])
            ->addColumn('created', 'integer', ['null' => false, 'default' => 0, 'limit' => 11, 'signed' => false, 'comment' => '创建时间',])
            ->addColumn('tenant_id', 'integer', ['null' => false, 'default' => 0, 'limit' => 11, 'signed' => false, 'comment' => '租户id',])
            ->addColumn('json', 'json', ['null' => true, 'comment' => 'json字段，存储自定义字段'])
            ->save();
    }

    public function down()
    {
        $this->table('task_work_order')->drop()->save();
    }
}
